package com.movia.bonbangsasu;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebSettings;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebView;
import android.webkit.WebSettings.RenderPriority;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {

	private WebView webView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		CookieSyncManager.createInstance(this);
		
		webView = (WebView)findViewById(R.id.webView1);
		String urlString = "http://bonbang4su.com";
		
		webView.getSettings().setJavaScriptEnabled(true);
		//webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
		webView.getSettings().setRenderPriority(RenderPriority.HIGH);
		webView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
		webView.getSettings().setLoadWithOverviewMode(true);
		webView.getSettings().setUseWideViewPort(true);
		webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
		webView.getSettings().setPluginState(WebSettings.PluginState.ON);
		webView.getSettings().setUseWideViewPort(true);
		webView.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
		webView.setWebViewClient(new bonBangSaSuWebViewClient());
		webView.setInitialScale(getScale());
		
		webView.loadUrl(urlString);
	}
	
	private int getScale()
    {
		Context mContext;
		mContext = getApplicationContext();
		
        Display display = ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        int width = display.getWidth();
        int PIC_WIDTH = webView.getRight() - webView.getLeft();
        Double val = new Double(PIC_WIDTH) / new Double(width);
        val = val * 100d;
        return val.intValue();
    }	
	
	class bonBangSaSuWebViewClient extends WebViewClient{
		public boolean shouldOverrideUrlLoading(WebView view, String url){
			view.loadUrl(url);
			return true;
		}
	}
	
	@Override
    public void onResume(){
    	super.onResume();
    	CookieSyncManager.getInstance().startSync();

    }
	
	 @Override
    public void onPause(){
    	super.onPause();
    	CookieSyncManager.getInstance().stopSync();

 	}	
	
}
